package ui.windows;

import entities.ViewShiftRequest;
import javax.swing.JPanel;
import ui.panels.ESRManagementPanel;
import ui.panels.HSRManagementPanel;

/**
 *
 * @author viev
 * EditShiftRequestDialog used show a dialog used to edit shift request.  
 */
public class EditShiftRequestDialog extends javax.swing.JDialog {

    /** Creates new form EditShiftRequestDialog */
    public EditShiftRequestDialog(RemedySchedulerFrame mainFrame, JPanel parentPanel) {
        this.mainFrame = mainFrame;
        this.parentPanel = parentPanel;
        try {
            headSRPanel = (HSRManagementPanel) parentPanel;
        } catch (Exception e) {
            employeeSRPanel = (ESRManagementPanel) parentPanel;
        }
        initComponents();
    }
    
    /**
     * 
     * @param view 
     * Set selected request.
     */
    public void setSelectedRequest(ViewShiftRequest view) {
        this.selectedRequest = view;
        if(selectedRequest != null) {
            String[] levels = {"Head", "Immediate Head", "Next Immediate Head", "Junior Head "};
            lbName.setText(view.getEmployeeName());
            lbDep.setText(view.getDepartmentName());
            lbRole.setText("Department Head");
            lbLevel.setText(levels[view.getLevel() - 1]);
            lbStartDate.setText(view.getStartDate().toString());
            lbEndDate.setText(view.getEndDate().toString());
            lbShift.setText(view.getShiftName()+"");
            lbCreateDate.setText(view.getCreateDate().toString());
            txaReason.setText(view.getReason());
            cbStatus.setSelectedIndex(view.getStatus() - 1);
        }
    }
    
    /**
     * Set status of a shift request.
     */
    private void set() {
        int requestID = selectedRequest.getShiftRequestID();
        int status = cbStatus.getSelectedIndex() + 1;
        if(headSRPanel != null) {
            headSRPanel.setStatusOfSR(requestID, status);
        } else {
            employeeSRPanel.setStatusOfSR(requestID, status);     
        }
        close();
    }
    
    /**
     * clear value of control components
     */
    private void clear() {
        lbName.setText("");
        lbCreateDate.setText("");
        lbDep.setText("");
        lbStartDate.setText("");
        lbEndDate.setText("");
        lbLevel.setText("");
        lbRole.setText("");
        lbShift.setText("");
        txaReason.setText("");
        cbStatus.setSelectedItem(null);
    }
    
    /**
     * close dialog.
     */
    private void close() {
        this.dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbName = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lbDep = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaReason = new javax.swing.JTextArea();
        jLabel12 = new javax.swing.JLabel();
        cbStatus = new javax.swing.JComboBox();
        lbRole = new javax.swing.JLabel();
        lbLevel = new javax.swing.JLabel();
        lbStartDate = new javax.swing.JLabel();
        lbEndDate = new javax.swing.JLabel();
        lbShift = new javax.swing.JLabel();
        lbCreateDate = new javax.swing.JLabel();
        bClose = new javax.swing.JButton();
        bOK = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Shift Request");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Request's Details", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 14))); // NOI18N

        jLabel1.setText("Name:");

        lbName.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbName.setText("value");

        jLabel3.setText("Department:");

        lbDep.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbDep.setText("value");

        jLabel5.setText("Role:");

        jLabel6.setText("Level:");

        jLabel7.setText("Start Date:");

        jLabel8.setText("End Date:");

        jLabel9.setText("Shift:");

        jLabel10.setText("Create Date:");

        jLabel11.setText("Reason:");

        txaReason.setColumns(20);
        txaReason.setRows(5);
        txaReason.setEnabled(false);
        jScrollPane1.setViewportView(txaReason);

        jLabel12.setText("Status:");

        cbStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "warning", "accept", "not accept" }));

        lbRole.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbRole.setText("value");

        lbLevel.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbLevel.setText("value");

        lbStartDate.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbStartDate.setText("value");

        lbEndDate.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbEndDate.setText("value");

        lbShift.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbShift.setText("value");

        lbCreateDate.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbCreateDate.setText("value");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(79, 79, 79)
                        .addComponent(cbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addGap(56, 56, 56)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbCreateDate)
                            .addComponent(lbShift)
                            .addComponent(lbEndDate)
                            .addComponent(lbStartDate)
                            .addComponent(lbLevel)
                            .addComponent(lbRole)
                            .addComponent(lbDep)
                            .addComponent(lbName))))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lbDep))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lbRole))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lbLevel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lbStartDate))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(lbEndDate))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(lbShift))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(lbCreateDate))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(cbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        bClose.setText("Close");
        bClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCloseActionPerformed(evt);
            }
        });

        bOK.setText("OK");
        bOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bOKActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bOK, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bClose, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bClose)
                    .addComponent(bOK))
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void bOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bOKActionPerformed
    set();
}//GEN-LAST:event_bOKActionPerformed

private void bCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCloseActionPerformed
    close();
}//GEN-LAST:event_bCloseActionPerformed
    private RemedySchedulerFrame mainFrame;
    private JPanel parentPanel;
    private ViewShiftRequest selectedRequest;
    private HSRManagementPanel headSRPanel;
    private ESRManagementPanel employeeSRPanel;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bClose;
    private javax.swing.JButton bOK;
    private javax.swing.JComboBox cbStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbCreateDate;
    private javax.swing.JLabel lbDep;
    private javax.swing.JLabel lbEndDate;
    private javax.swing.JLabel lbLevel;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lbRole;
    private javax.swing.JLabel lbShift;
    private javax.swing.JLabel lbStartDate;
    private javax.swing.JTextArea txaReason;
    // End of variables declaration//GEN-END:variables
}
